// aenpc.txt
// Like basicnpc, but can also project a damaging AE. 
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Type of AE
//		0 - fire, does 1-6 * level
//		1 - cold, does 1-8 * level
//		2 - energy, does 1-10 * level
//		3 - slow
//		4 - debuff
//		5 - daze
//		6 - charm
//		7 - fear
//		8 - acid
//      9 - lightning aura
//		10 - poison
// 		11 - cleave (1-8 dam per level)
//   Cell 4 - Range of AE, Left at default of 4 if 0
//   Cell 5 - Number of state when talked to. Plays default text if 0.
//   Cell 6 - % chance of using AE, defaults to 50% if left at 0

begincreaturescript;

variables;

short i,target;
short last_abil;
short ae_freq = 100;
short ae_range = 6;
short mess1 = 0;
short mess2 = 0;
short mess3 = 0;
short mess4 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Dark Golem");
	set_level(ME,20);
	set_boss_level(ME,2);
	
	last_abil = get_current_tick();
	if (get_memory_cell(4) != 0)
		ae_range = get_memory_cell(4);

	if (gf(36,1) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	if (gf(36,13) == 0) 
		end();
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 40)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((mess1 == 0) && (get_health(ME) < get_max_health(ME) - 100)) {
		mess1 = 1;
		ae_freq = 2;
		begin_talk_mode(43);
		}
	if ((mess3 == 0) && (get_health(ME) < get_max_health(ME) / 2) && (gf(36,1) == 0) && (char_ok(39)) && (get_attitude(39) >= 10)) {
		mess3 = 1;
		begin_talk_mode(46);
		}
	if ((mess4 == 0) && (mess1 > 0) && (((get_health(ME) < get_max_health(ME) / 4) && (get_attitude(ME) >= 10)) || (gf(36,1) > 0))) {
		mess4 = 1;
		ae_freq = 0;
		set_attitude(ME,10);
		begin_talk_mode(47);
		}
		
	if ((is_combat()) && (mess1 > 0) && 
	  (tick_difference(last_abil,get_current_tick()) > ae_freq)) {
		run_char_animation(2,1,35);	
		  	place_particle_num(ME,4,6,8);
			print_named_str(ME,"sprays out a burning gas.");
			pc_heard_sound_delay(177,250);			
	  		create_missile_spiral(142,40,ae_range,2);
			status_nearby(6,ae_range,6,0);
	  		damage_nearby(30 + get_ran(1,0,30),ae_range,5,0);


		last_abil = get_current_tick();
		end();
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
		print_str("Talking: The creature can't talk.");
break;